// 兄弟组件间的通讯
import React from 'react'
import ReactDOM from 'react-dom'


// 父组件
class Counter extends React.Component {
    // 提供共享状态
    state = {
        count:0
    }

    addNum = ()=>{
        this.setState({
            count:this.state.count+1
        })
    }

    render() {
        return (
            <div>
                <Child1 count={this.state.count} />
                <Child2 addNum={this.addNum} />
            </div>
        )
    }
}

const Child1 = (props) => {
    return (
        <h1>记数器：{props.count}</h1>
    )
}

const Child2 = (props) => {
    return (
        <button onClick={()=>props.addNum()}> +1</button>
    )
}

ReactDOM.render(<Counter />, document.getElementById('root'))